<?php
/**
 * Created by PhpStorm.
 * User: XYX
 * Date: 2017/6/3
 * Time: 19:38
 */

namespace App\SoftImage;


use Intervention\Image\Facades\Image;

class SoftImage
{
    public  $file;
    public function __construct($file)
    {
        $this->file = $file;
    }
    public static function title ($file){
        return (new static($file))->titleimg();
    }
    public static function image ($file){
        return (new static($file))->softimg();
    }
    public static function cover ($file){
        return (new static($file))->coverimg();
    }
    public static function url ($file){
        return (new static($file))->urlimg();
    }
    public static function img ($file){
        return (new static($file))->imgee();
    }
    public function titleimg(){
        $destinationPath = 'image/title/';
        $titleimage = $this->file;
        $titleimagename = \Auth::user()->id.'_'.time().$titleimage->getClientOriginalName();
        $titleimage->move($destinationPath,$titleimagename);
        Image::make($destinationPath.$titleimagename)->fit(100)->save();
        return ['title_image'=>'/'.$destinationPath.$titleimagename];
    }
    public function softimg(){
        $destinationPath = 'image/soft/';
        $titleimage = $this->file;
        $titleimagename = \Auth::user()->id.'_'.time().$titleimage->getClientOriginalName();
        $titleimage->move($destinationPath,$titleimagename);
        Image::make($destinationPath.$titleimagename)->fit(320,180)->save();
        return ['award_image'=>'/'.$destinationPath.$titleimagename];
    }
    public function coverimg(){
        $destinationPath = 'image/cover/';
        $titleimage = $this->file;
        $titleimagename = \Auth::user()->id.'_'.time().$titleimage->getClientOriginalName();
        $titleimage->move($destinationPath,$titleimagename);
        Image::make($destinationPath.$titleimagename)->fit(320,180)->save();
        return ['cover_image'=>'/'.$destinationPath.$titleimagename];
    }
    public function urlimg(){
        $destinationPath = 'image/banner/';
        $titleimage = $this->file;
        $titleimagename = \Auth::user()->id.'_'.time().$titleimage->getClientOriginalName();
        $titleimage->move($destinationPath,$titleimagename);
        Image::make($destinationPath.$titleimagename)->fit(320,180)->save();
        return ['image_url'=>'/'.$destinationPath.$titleimagename];
    }
    public function imgee(){
        $destinationPath = 'image/banner/';
        $titleimage = $this->file;
        $titleimagename = \Auth::user()->id.'_'.time().$titleimage->getClientOriginalName();
        $titleimage->move($destinationPath,$titleimagename);
        Image::make($destinationPath.$titleimagename)->fit(320,180)->save();
        return ['image'=>'/'.$destinationPath.$titleimagename];
    }

}